package com.admin.service.serviceimpl;

import com.admin.mapper.ContentNewsMapper;
import com.admin.service.ContentNewsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fegin.bean.admin.ContentNews;
import com.util.Respons.ResponseMsg;
import com.util.exception.CommonException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 公司新闻 服务实现类
 * </p>
 *
 * @author 卫星
 * @since 2019-03-04
 */
@Service
public class ContentNewsServiceImpl extends ServiceImpl<ContentNewsMapper, ContentNews> implements ContentNewsService {

    @Autowired
    private ContentNewsMapper contentNewsMapper;

    /**
     * 查看新闻分页数据
     *
     * @param news
     * @param page
     * @return
     */
    @Override
    public Page<ContentNews> findByCondition(ContentNews news, Page page) {
        List<ContentNews> list = contentNewsMapper.findByCondition(news, page);
        return page.setRecords(list);
    }

    /**
     * 假删除新闻
     *
     * @param contentNews
     * @return
     */
    @Override
    public Integer deleteByPrimaryKey(ContentNews contentNews) {
        if (contentNews.getId() == null) {
            throw new CommonException(ResponseMsg.MISS_PARAM);
        }
        contentNews.setIsDeleted(true);
        return contentNewsMapper.updateById(contentNews);
    }
}
